package rabbitmq

import (
	util "gin-easy/pkg/until"
	"github.com/streadway/amqp"
)

// 生产着
func Send(queueName string, data map[string]interface{}, taskName string) {
	body := map[string]interface{}{
		"taskName": taskName,
		"data":     data,
	}
	d := util.MapToJson(body)
	qn := QuenuList[queueName]
	q, err := RabbitmqCh.QueueDeclare(
		qn.name,       // name
		qn.durable,    // durable
		qn.autoDelete, // delete when unused
		qn.exclusive,  // exclusive
		qn.nowWait,    // no-wait
		qn.args,       // arguments
	)
	failOnError(err, "Failed to declare a queue")

	err = RabbitmqCh.Publish(
		"",     // exchange
		q.Name, // routing key 上面交换机为空 就根据队列名来指定
		false,  // mandatory
		false,
		amqp.Publishing{
			DeliveryMode: amqp.Persistent,
			ContentType:  "text/plain",
			Body:         []byte(d),
		})
	failOnError(err, "Failed to publish a message")
}
